﻿using System;
using System.Collections.Generic;

namespace LeetCodeSolutions
{
    public class LeetCode961: LeetCodeBase
    {
        public override void Execute()
        {
            int[] nums = new int[] { 2, 6, 2, 1, };
            CommonFuntions.Print(RepeatedNTimes(nums));
        }

        /// <summary>
        /// 961. 在长度 2N 的数组中找出重复 N 次的元素
        /// </summary>
        public int RepeatedNTimes(int[] nums)
        {
            int len = nums.Length;
            Random random = new Random();
            int a;
            int b;
            while (true)
            { 
                a = random.Next(0, len);
                b = random.Next(0, len);

                if (a != b && nums[a] == nums[b])
                {
                    return nums[a];
                }
            }
        }
    }
}
